package com.ashleyleung.jetpack_b_station.taobao

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ashleyleung.jetpack_b_station.R
import com.ashleyleung.jetpack_b_station.domain.MapData
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.item_on_sell.view.*

/**
 * @author lxy
 * @name
 * @class describe
 * @date 2022-06-29
 * Copyright (c)  Guangzhou GCI Science & Technology Co., Ltd.All rights reserved
 */
class OnSellListAdapter : RecyclerView.Adapter<OnSellListAdapter.InnerHolder>() {
    private val mContentList = arrayListOf<MapData>()

    class InnerHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): OnSellListAdapter.InnerHolder {
        val itemView =
        LayoutInflater.from(parent.context).inflate(R.layout.item_on_sell,parent,false)
        return InnerHolder(itemView)
    }

    override fun onBindViewHolder(holder: OnSellListAdapter.InnerHolder, position: Int) {
        holder.itemView.apply{
            with(mContentList[position]){
                itemTitleTv.text =title
                offPriceTv.text= String.format("¥%.2f",zk_final_price.toFloat()-coupon_amount)
                Glide.with(context).load("https:$pict_url").into(itemCoverIv)

            }
        }


    }

    override fun getItemCount(): Int {
       return  mContentList.size
    }

    fun setData(it: List<MapData>?) {
        mContentList.clear()
        if (it != null) {
            mContentList.addAll(it)
        }
        notifyDataSetChanged()
    }
}